//C14.20:tempmemb.cpp -- template members
#include <iostream>
using std::cout;
using std::endl;
template<typename T>

class Beta
{
    template<typename V>    // nested template class member
    class Hold
    {
        V val;
        public:
            Hold(V v = 0) : val(v){}
            void Show() const { cout << val << endl; }
            V Value() const { return val; }
    };
    Hold<T> q;      // template object
    Hold<int> n;    // template object
    public:
        Beta(T t, int i) : q(t), n(i){} 
        template<typename U>    // template method
        U blab(U u, T t) { return (n.Value() + q.Value()) * u / t; }
        void Show() const { q.Show(); n.Show(); }
};

int main(void)
{
    Beta<double> guy(3.5, 3);
    cout << "T was set to double\n";
    guy.Show();

    cout << "V was set to T, which is double, then V was set to int\n";
    cout << guy.blab(10, 2.3) << endl;
    cout << "U was set to int\n";
    cout << guy.blab(10.0, 2.3) << endl;
    cout << "U was set to double\n";
    cout << "Done.\n";
}